package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.db.Question;
import com.tanhua.dubbo.mapper.QuestionMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @version 1.0
 * @author： xtr
 * @date： 2021-03-07 19:22
 */
@Service
public class QuestionApiImpl implements QuestionApi {
    @Autowired
    private QuestionMapper questionMapper;
    @Override
    public Question findByUserId(Long userId) {
        QueryWrapper<Question> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        Question question = questionMapper.selectOne(queryWrapper);
        return question;
    }

    /**
     * 更新陌生人问题
     * @param questionApiByUserId
     */
    @Override
    public void update(Question questionApiByUserId) {
        questionMapper.updateById(questionApiByUserId);
    }

    /**
     * 保存陌生人问题
     *
     * @param questionApiByUserId
     */
    @Override
    public void save(Question questionApiByUserId) {
        questionMapper.insert(questionApiByUserId);
    }
}
